/**
 * 1. 初始条件
 */
var xunInitialConditions = {};


function xunChangeICview(id){
	Ext.getCmp('xunICcard1_xun').setActiveItem(id);
	Ext.getCmp('xunICcard2').setActiveItem(id);
	Ext.getCmp('xunICcard3').setActiveItem(id);
}

function xunICHistory(){
	var output = new Array();
	var inspec = 1;
	for(var j=2012;j<2017;j++){
		output.push({id:inspec++, index1: j, index2:ra(10), index3:ra(10), index4:ra(10)});
	}
	return output;
}

function xunICForecast(){
	var output = new Array();
	var inspec = 1;
	for(var j=1;j<13;j++){
		output.push({id:inspec++, index1: j+'月', index2:ra(10), index3:ra(10), index4:ra(10)});
	}
	return output;
}

function xunICDisplayData(){
	xunICReservior = [
		{id:'1' ,index1: '洪门', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'2', index1: '廖坊', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()}
	];
	xunICSection = [
		{id:'1', index1: '沙子岭', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'2', index1: '南丰', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'3', index1: '南城', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'4', index1: '黎川', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'5', index1: '廖家湾', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
//		{id:'5', index1: '橡胶梖', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'6', index1: '娄家村', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'7', index1: '焦石', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()},
		{id:'8', index1: '李家渡', index2:ra(100), index3: ra(100), index4:ra(100), index5:xunICHistory(), index6:xunICForecast()}
	];	
	xunICfill();
}

function xunICDisplayData2(){
	var link = "szy/dispatch/wateroptimum/xunInitialCondition";
	$.ajax({
	//	url: "http://localhost:8080/Springwap/"+link+".shtml",
		url: config.URL+link,
		type: "post",
		data: {},
		dataType: "json",
		success: function(result) {
			xunInitialConditions = result;
			xunICReservior = xunInitialConditions.index1;
			xunICSection = xunInitialConditions.index2;
			xunICfill();
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			Ext.Msg.alert('提示', '读取初始条件时发生了错误！');
		}
	});
}

function xunICfill(){
	Ext.data.StoreManager.lookup('xunICstore1_xun').setData(xunICReservior);
	Ext.getCmp('xunICgrid1_xun').getSelectionModel().select(0); 
	Ext.data.StoreManager.lookup('xunICstore1_2').setData(xunICSection);
	Ext.getCmp('xunICgrid2').getSelectionModel().select(0); 
}


Ext.define('Admin.view.needwater.xunpack.subpage.initialConditions',{
	extend:'Ext.panel.Panel',
	xtype:'xunInitialConditions',
	//起别名
	alias:'xunInitialConditions',	
	require:[],
	user:[],
	userCLs:'big-100 small-100',
	layout: {
        type: 'hbox',
        align: 'stretch'
    },
	padding: '10 0 0 0',
	items:[{
		xtype:'panel',
		border:false,
		layout: {
	        type: 'vbox',
	        align: 'stretch'
	    },
		items:[{
			xtype: 'panel',
		    border: false,
		    margin: '10 10 10 10',
            layout: 'card',
            id: 'xunICcard1_xun',
			items: [{
				xtype: 'grid',
				border: true,
				id: 'xunICgrid1_xun',
			    store: {xtype:'store', storeId: 'xunICstore1_xun'},
			    columns: [
			        { text: '水库', dataIndex: 'index1', width: '24%', minWidth: 100, align: 'center'},
			        { text: '初始水位', dataIndex: 'index2', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			        { text: '期末水位', dataIndex: 'index3', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			        { text: '蓄变量', dataIndex: 'index4', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' }
			    ],
			    dockedItems: [{
			        xtype: 'toolbar',
			        dock: 'top',
			        height: 30,
			        items: [
			            { xtype: 'label', html: '<span style="font-size:14px;margin-left:5px;cursor: pointer;font-weight:bold;" onclick="xunChangeICview(0)">►水库</span> | <span style="font-size:14px;margin-left:5px;cursor: pointer;font-weight:normal;" onclick="xunChangeICview(1)">断面</span>' }
			        ]
			    }],
			    listeners: {
			    	afterrender : {
			            fn: function(obj, eOpts){ 
			            	this.getSelectionModel().select(0); 
			            }
			        },
			        select:{
			        	fn: function(obj, eOpts){ 
			            	var index = this.getSelectionModel().getSelection();
			            	document.getElementById("xun_xunICheadshow0").innerHTML = "历史信息 [ "+index[0].get('index1')+" ]";
			            	document.getElementById("xun_xunICheadshow2").innerHTML = "来水预报 [ "+index[0].get('index1')+" ]";
			            	Ext.data.StoreManager.lookup('xunICstore1_4').setData(index[0].get('index5'));
			            	Ext.data.StoreManager.lookup('xunICstore1_3').setData(index[0].get('index6'));
			            }
			        }
			    }
			},{
				xtype: 'grid',
				border: true,	
				id: 'xunICgrid2',			
				store: {xtype:'store', storeId: 'xunICstore1_2'},
			    columns: [
			    	{ text: '断面', dataIndex: 'index1', width: '24%', minWidth: 100, align: 'center' },
			        { text: '初始流量', dataIndex: 'index2', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)'  },
			        { text: '最小生态流量', dataIndex: 'index3', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)'  },
			        { text: '最大流量', dataIndex: 'index4', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)'  }
			    ],
			    dockedItems: [{
			        xtype: 'toolbar',
			        dock: 'top',
			        height: 30,
			        items: [
			            { xtype: 'label', html: '<span style="font-size:14px;margin-left:5px;cursor: pointer;font-weight:normal;" onclick="xunChangeICview(0)">水库</span> | <span style="font-size:14px;margin-left:5px;cursor: pointer;font-weight:bold;" onclick="xunchangeICview(1)">►断面</span>' }
			        ]
			    }],
			    listeners: {
			    	afterrender : {
			            fn: function(obj, eOpts){ 
			            	Ext.getCmp('xunICgrid2').getSelectionModel().select(0); 
			            }
			        },
			        select:{
			        	fn: function(obj, eOpts){ 
			            	var index = Ext.getCmp('xunICgrid2').getSelectionModel().getSelection(); 
			            	document.getElementById("xunICheadshow1").innerHTML = "历史信息 [ "+index[0].get('index1')+" ]";
			            	document.getElementById("xunICheadshow3").innerHTML = "来水预报 [ "+index[0].get('index1')+" ]";
			            	Ext.data.StoreManager.lookup('xunICstore1_5').setData(index[0].get('index5'));
			            	Ext.data.StoreManager.lookup('xunICstore1_3_2').setData(index[0].get('index6'));
			            }
			        }
			    }
			}],
			flex:1
		},{
			xtype: 'panel',
		    border: false,
		    margin: '10 10 10 10',
            layout: 'card',
        //    height: 232,
            id: 'xunICcard2',
			items: [{
				xtype: 'grid', 
				border: true,
			    store: {xtype:'store', storeId: 'xunICstore1_4'},
			    columns: [
			        { text: '时间', dataIndex: 'index1', width: '24%', minWidth: 100, align: 'center' },
			        { text: '初始水位', dataIndex: 'index2', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			        { text: '期末水位', dataIndex: 'index3', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			        { text: '蓄变量', dataIndex: 'index4', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' }
			    ],
			    dockedItems: [{
			        xtype: 'toolbar',
			        dock: 'top',
			        height: 30,
			        items: [
			            { xtype: 'label', html: '<span id="xun_xunICheadshow0" style="font-size:14px;margin-left:5px;">历史信息</span>' }
			        ]
			    }]
			},{
				xtype: 'grid', 
				border: true,
				store: {xtype:'store', storeId: 'xunICstore1_5'},
			    columns: [
			    	{ text: '时间', dataIndex: 'index1', width: '24%', minWidth: 100, align: 'center' },
			        { text: '初始流量', dataIndex: 'index2', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			        { text: '最小生态流量', dataIndex: 'index3', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			        { text: '最大流量', dataIndex: 'index4', width: '25%', minWidth: 100, align: 'center', formatter: 'round(3)' }
			    ],
			    dockedItems: [{
			        xtype: 'toolbar',
			        dock: 'top',
			        height: 30,
			        items: [
			            { xtype: 'label', html: '<span id="xunICheadshow1" style="font-size:14px;margin-left:5px;">历史信息</span>' }
			        ]
			    }]
			}],
			flex:1
		}],
	    flex:1       
	},{
		xtype:'panel',
		layout: 'card',
        id: 'xunICcard3',
		margin: '10 10 10 10',
	//	height: 572,
		items: [{
			xtype: 'grid', 
			border: true,
			store: {xtype:'store', storeId: 'xunICstore1_3'},
			columns: [
				{ text: '月份', dataIndex: 'index1', width: '49%', minWidth: 100, align: 'center' },
			//    { text: '区间A', dataIndex: 'index2', width: '33%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			    { text: '流量', dataIndex: 'index3', width: '50%', minWidth: 100, align: 'center', formatter: 'round(3)' }],
			
			dockedItems: [{
		    xtype: 'toolbar',
		    dock: 'top',
		    height: 30,
		    items: [
		        { xtype: 'label', html: '<span id="xun_xunICheadshow2" style="font-size:14px;margin-left:5px;">来水预报</span>' }
		        ]
		    }]     	
		},{
			xtype: 'grid', 
			border: true,
			store: {xtype:'store', storeId: 'xunICstore1_3_2'},
			columns: [
				{ text: '月份', dataIndex: 'index1', width: '49%', minWidth: 100, align: 'center' },
			//    { text: '区间A', dataIndex: 'index2', width: '33%', minWidth: 100, align: 'center', formatter: 'round(3)' },
			    { text: '流量', dataIndex: 'index3', width: '50%', minWidth: 100, align: 'center', formatter: 'round(3)' }],
			dockedItems: [{
		    xtype: 'toolbar',
		    dock: 'top',
		    height: 30,
		    items: [
		        { xtype: 'label', html: '<span id="xunICheadshow3" style="font-size:14px;margin-left:5px;">来水预报</span>' }
		        ]
		    }]     	
		}],
		flex:1
	}],
	listeners: {
		boxready: {
			fn: function(){
				xunICDisplayData2();
			}
		}
	}
});